<template>
  <div id="RecordsList">
    <!-- 头部 -->
    <div class="main-header">
      <span>my name is {{ $store.state.user.uname }}...age is {{ $store.state.ages }}</span>
      <el-button icon="el-icon-circle-plus-outline" circle @click="dialogFormVisible=true"></el-button>
    </div>
    <!-- 列表 -->
    <el-table :data="obj.records" border stripe size="mini" max-height="50%">
      <el-table-column prop="rcId" label="编号"></el-table-column>
      <el-table-column prop="amount" label="金额"></el-table-column>
      <el-table-column prop="rcTypeNm" label="记账类别"></el-table-column>
      <el-table-column prop="recTm" label="记账时间"></el-table-column>
      <el-table-column prop="comment" label="备注"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button class="el-icon-edit" circle size="mini"
            @click="handleEdit(scope.$index, scope.row)"></el-button>
          <el-button class="el-icon-delete" circle size="mini" type="danger"
            @click="handleDelete(scope.$index, scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      class="pagination"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="obj.current"
      :page-sizes="[10, 50, 100, 200]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="obj.total">
    </el-pagination>
    <!-- 详情 -->
    <el-dialog title="个人账单" :visible.sync="dialogFormVisible">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="金额">
          <el-input  placeholder="请输入金额" v-model="form.amount" oninput="if(value.indexOf('.')>0) {value=value.slice(0,value.indexOf('.')+3)}">
            <template slot="prepend">-</template>
          </el-input>
        </el-form-item>
        <el-form-item label="活动时间">
          <el-col :span="11">
            <el-date-picker type="date" placeholder="选择日期" v-model="form.rec_tm" style="width: 80%;"></el-date-picker>
          </el-col>
          <el-col class="line" :span="2">-</el-col>
          <el-col :span="11">
            <el-time-picker placeholder="选择时间" v-model="form.date2" style="width: 100%;"></el-time-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="描述">
          <el-input type="textarea" v-model="form.comment"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button @click="dialogFormVisible=false">取消</el-button>
        </el-form-item>
      </el-form>

      <el-button slot="reference">记一笔</el-button>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'RecordsList',
  data() {
    return {
      obj: {},
      pagination: {
        size : 10,
        current : 1
      },
      form: {
        rc_id: 'RCYYYYMMDD000',
        rc_id_rel: '1',
        amount: 0,
        rcRecordType: '1',
        rc_type: 11,
        comment: '',
        rec_psn: 1,
        rec_tm: ''
      },
      dialogFormVisible: false,
    }
  },
  methods: {
    //添加
    onSubmit() {
      console.log('submit!');
    },
    //修改
    handleEdit(index, obj){
      console.log(index, obj);
      this.dialogFormVisible=true
    },
    //删除
    handleDelete(index, obj){
      console.log(index, obj);
    },
    //跳转
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pagination.size = val
      this.paging()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.pagination.current = val
      this.paging()
    },
    paging(){
      this.$http.get('/records/getRecordsPage', {
        params: this.pagination
      })
      .then(response => {
        console.log(response);
        this.obj = response.data.obj;
      })
      .catch(error => {
        console.error(error);
      });
    }
  },

  mounted(){
    this.paging()
  },
}
</script>

<style scoped>
.main-header{
  width: 100%;
}
.el-table{
  margin-top: 10px;
}
.el-pagination{
  float: right;
  margin-top: 10px;
}

</style>
